package com.atguigu.gmall.mq.receiver;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/4 17:20
 */
@Component
@Configuration
public class ConfirmReceiver {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue.confirm", declare = "true", autoDelete = "false"),
            exchange = @Exchange(value = "exchange.confirm"),
            key = {"routing.confirm"}))
    public void getMsg(String msg, Message message, Channel channel) throws IOException {
        System.out.println(msg);

        //    进行消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
